package wheres.the.party;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

public class Model{

	public Model(){
	}
	
	public String getSignupAnswer(String username, String password){
		String s = "signup.php?username="+username+"&password="+password;
		return getServerAnswer(s);
	}
	
	public String getLoginAnswer(String username, String password){
		String s = "login.php?username="+username+"&password="+password;
		return getServerAnswer(s);
	}	
	
	private String getServerAnswer(String page){
    	String str = "***";

        try{
    		HttpClient hc = new DefaultHttpClient();
    		HttpGet post = new HttpGet("http://www.pphoenix.heliohost.org/"+page);

    		HttpResponse rp = hc.execute(post);

    		if(rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
    			str = EntityUtils.toString(rp.getEntity());
    		}
    	}catch(IOException e){
    		e.printStackTrace();
    	}  
    	
    	return str;
    }
}